/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2017-07-21 11:42:21
 * @Copyright: 2017 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
package com.itttq.gshop.pbpm.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Lang;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;

import com.itttq.gshop.domain.po.UserInfoPo;
import com.itttq.gshop.domain.to.IndexStatTo;
import com.itttq.gshop.pbpm.cmpt.mybatis.CustomInLanguage;
import com.itttq.gshop.pbpm.provider.UserInfoSqlProvider;

@Mapper
public interface IUserInfoMapper {
	/**
	 * 新增UserInfoPo对象，返回新增对象的数量
	 * 
	 * @param UserInfoPo
	 * @Author 迷蝶
	 * @return Integer
	 */
	@InsertProvider(type=UserInfoSqlProvider.class,  method="addUserInfo") 
	@Options(useGeneratedKeys = true, keyProperty = "id")
	public Integer addUserInfo(UserInfoPo userInfo);

	/**
	 * 更新UserInfoPo对象
	 * 
	 * @param userInfoPo
	 * @Author 迷蝶
	 * @return Integer
	 */
	@UpdateProvider(type=UserInfoSqlProvider.class,  method="updateUserInfo") 
	public Integer updateUserInfo(UserInfoPo userInfo);

	/**
	 * 根据手机号更新密码
	 * 
	 * @param userInfoPo
	 * @Author 迷蝶
	 * @return Integer
	 */
	@Update("UPDATE user_info SET password=#{password}, salt=#{salt} WHERE mobile=#{mobile}") 
	public Integer updatePwdByMobile(UserInfoPo userInfo);
	
	/**
	 * 根据ID删除UserInfoPo对象
	 * 
	 * @param id
	 * @Author 迷蝶
	 * @return Integer
	 */
	@DeleteProvider(type=UserInfoSqlProvider.class,  method="delUserInfo") 
	public Integer delUserInfoById(Integer id);

	/**
	 * 根据IDS删除UserInfoPo对象
	 * 
	 * @param ids
	 * @Author 迷蝶
	 * @return List<UserInfoPo>
	 */
	@Lang(CustomInLanguage.class)
	@Delete("DELETE FROM user_info WHERE id IN (#{ids})")
	public Integer delUserInfoByIds(@Param("ids") List<Integer> ids);
	
	/**
	 * 根据条件查找UserInfoPo对象，默认根据ID降序
	 * 
	 * @param userInfoPo
	 * @Author 迷蝶
	 * @return List<UserInfoPo>
	 */
	@SelectProvider(type=UserInfoSqlProvider.class,  method="findUserInfos") 
	public List<UserInfoPo> findUserInfos(UserInfoPo userInfo);

	/**
	 * 获取所有用户信息，只获取了部分字段值
	 * 
	 * @Author 迷蝶
	 * @return List<UserInfoPo>
	 */
	@Select("select id,birthday,email,gender,member_score,mobile,realname,telephone,username,head,promo_code from user_info") 
	public List<UserInfoPo> findAllUsers();
	
	/**
	 * 根据条件查找记录总数
	 * 
	 * @param userInfoPo
	 * @Author 迷蝶
	 * @return Integer
	 */
	@SelectProvider(type=UserInfoSqlProvider.class,  method="findUserInfoCount") 
	public Integer findUserInfoCount(UserInfoPo userInfo);

	/**
	 * 根据ID查找UserInfoPo对象
	 * 
	 * @param id
	 * @Author 迷蝶
	 * @return UserInfoPo
	 */
	@SelectProvider(type=UserInfoSqlProvider.class,  method="findUserInfoById") 
	public UserInfoPo findUserInfoById(Integer id);
	
	/**
	 * 获取今天新增用户
	 * 
	 * @Author 迷蝶
	 * @return IndexStatTo
	 */
	@Select("select count(*) as countToday from user_info where TO_DAYS(NOW( )) = TO_DAYS(create_time)") 
	public IndexStatTo findUserCountToday();
}